package com.bjsxt.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MapControl {


    private static final int Error_Code =500;
    private static final int Success_Code =0;



    Map<String,Object> paramMap = new HashMap<>();

    private MapControl(){

    }

    public static MapControl getInstance(){
        return new MapControl();
    }

    public Map<String,Object> getMap(){
        return paramMap;
    }

    public MapControl put(String key, Object values){
        paramMap.put(key,values);
        return this;
    }

    public MapControl put(Map<String,Object>map){
        //注意设置map.entry的泛型
        for(Map.Entry<String,Object> entry :map.entrySet()){
            paramMap.put(entry.getKey(),entry.getValue());
        }
        return this;
    }

    public MapControl success(){
        return  this.put("msg", "操作成功").put("code",Success_Code);
    }

    public MapControl success(String str){
        return  this.put("msg",str).put("code",Success_Code);
    }

    public MapControl error(){
        return  this.put("msg","操作失败").put("code",Error_Code);
    }
    public MapControl error(String str){
        return  this.put("msg",str).put("code",Error_Code);
    }


    public MapControl page(List<?> data,Integer count,int code){
        return  this.put("msg", "返回成功").put("code",code).put("count",count).put("data",data);
    }

    public MapControl page(List<?> data,Integer count){
        return  this.put("msg", "返回成功").put("code",Success_Code).put("count",count).put("data",data);
    }

    public MapControl add(String key,Object object){
        return this.put(key,object);
    }

}
